<template>
  <el-form :inline="true">
    <el-form-item label="一级分类">
      <el-select
        placeholder="请选择"
        @change="select1Handler"
        v-model="categoryStore.c1Id"
        :disabled="scene"
      >
        <el-option
          v-for="c1 in categoryStore.c1Arr"
          :key="c1.id"
          :label="c1.name"
          :value="c1.id"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="二级分类">
      <el-select
        placeholder="请选择"
        @change="select2Handler"
        v-model="categoryStore.c2Id"
        :disabled="scene"
      >
        <el-option
          v-for="c2 in categoryStore.c2Arr"
          :key="c2.id"
          :label="c2.name"
          :value="c2.id"
          
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="三级分类" >
      <el-select placeholder="请选择" v-model="categoryStore.c3Id" :disabled="scene">
        <el-option
          v-for="c3 in categoryStore.c3Arr"
          :key="c3.id"
          :label="c3.name"
          :value="c3.id"
        ></el-option>
      </el-select>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { useCategoryStore } from "@/stores/catgory";
import { onMounted, ref } from "@vue/runtime-core";

//获取仓库
let categoryStore = useCategoryStore();
//获取props决定显示select禁用与否
defineProps(['scene'])

//挂载调用一级分类请求api
onMounted(() => {
  categoryStore.getCategory1List();
});

//选一级标题的时候的回调
const select1Handler = () => {
  categoryStore.c2Id = "";
  categoryStore.c2Arr = [];
  categoryStore.c3Id = "";
  categoryStore.c3Arr = [];
  categoryStore.getCategory2List();
};
//选二级标题的时候的回调
const select2Handler = () => {
  categoryStore.c3Id = "";
  categoryStore.c3Arr = [];
  categoryStore.getCategory3List();
};
</script>

<script lang="ts">
export default {
  name: "Catgory",
};
</script>

<style scoped>
</style>